<?php

declare(strict_types=1);

namespace App\Controller\delivery;
use App\Controller\BaseController;
use App\Model\Payment;
use App\Model\RechargeGoods;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use App\Common\Response\SystemCode;
use App\Service\delivery\StatisticsService;

#[AutoController]
class UserStatisticsController  extends BaseController
{

    #[Inject]
    private StatisticsService $statisticsService;
    /**
     * 推广列表
     */
    public function Index(RequestInterface $request)
    {
        $params         = $request->query();
        $applet_ids     = $params['applet_ids'] ?? '';

        if($applet_ids == 1){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择小程序');
        }

        $data = $this->statisticsService->userSearch($request->query());

        return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$data);
    }

    public function getUserBuy(RequestInterface $request)
    {
        $params = $request->post();
        if(empty($params['user_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择用户');
        }

        if(empty($params['applet_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择小程序');
        }
        $data = $this->statisticsService->getUserBuy($params);

        return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$data);
    }

    public function getUserRecharge(RequestInterface $request)
    {
        $params = $request->post();
        if(empty($params['user_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择用户');
        }

        if(empty($params['applet_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择小程序');
        }
        $data = $this->statisticsService->getUserRecharge($params);

        return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$data);
    }

    public function getUserView(RequestInterface $request)
    {
        $params = $request->post();
        if(empty($params['user_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择用户');
        }
        if(empty($params['applet_id'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择小程序');
        }
        if(empty($params['view_at'])){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择时间');
        }

        $result = $this->statisticsService->getUserView($params);
        if($result['code'] == SystemCode::SYSTEM_SUCCESS){
            return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$result['data']);
        }else{
            return $this->response(SystemCode::SYSTEM_ERROR, $result['message']);

        }
    }

    public function getSearchSpread(RequestInterface $request)
    {
        $params         = $request->post();
        $applet_id     = $params['applet_id'] ?? '';

        if(empty($applet_id)){
            return $this->response(SystemCode::SYSTEM_ERROR, '请选择小程序');
        }

        $data = $this->statisticsService->getSearchSpread($params);

        return $this->response(SystemCode::SYSTEM_SUCCESS, '请求成功',$data);
    }
}